<!DOCTYPE html>
<html>
<head>
    <title>攻略系列</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link href="/travelComment_files/mobile+css+head_mobile+css+ui_mobile+css+ui+slider.default^Zl0^1526627473.css"
          rel="stylesheet" type="text/css">
    <link href="/travelComment_files/note.css" rel="stylesheet" type="text/css">
    <link href="/travelComment_files/swiper-3.3.1.min.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategyCatalogs.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>

    <script>
        $(function () {
            /*params中仅包含strategyId*/
            var params = getParams();
            var strategyId = params.strategyId;
            /*如果没有攻略id,说明非正常跳转,直接返回*/
            if (!strategyId) {
                return;
            }
            /*抽取基本路径*/
            var baseUrl = '/strategies/' + strategyId;

            /*获取攻略基本信息*/
            $.get(baseUrl, function (data) {
                $('.title').html(data.title);
            });

            /*获取攻略分类列表*/
            $.get(baseUrl + "/catalogs", function (data) {
                var index = 1;
                $('.catalogs').renderValues({list: data}, {
                    getName: function (item, value) {
                        $(item).html(index++ + "/" + value);
                    },
                    getHref: function (item, value) {
                        var href = $(item).data("href");
                        $(item).attr("href", href + value);
                    }
                });
            });

            /*获取骡友标签*/
            $.get(baseUrl + '/tags', function (data) {
                var temp = {list: data};
                $('.tag').renderValues({list: data});
            })

            /*用于存储攻略评论的数组*/
            var commentData = [];
            /*默认分页数*/
            var pages = 1;
            /*分页*/
            var currentInput = $("[name=currentPage]");
            var pageSize = $("[name=pageSize]");

            /*默认加载一次游记评论分页查询*/
            query();

            /*分页查询函数*/
            function query() {
                /*当前页*/
                var pageNum = currentInput.val();
                /*页面容量*/
                var pageSizeVal = pageSize.val();
                $.get(baseUrl + '/comments', {currentPage: pageNum, pageSize: pageSizeVal}, function (data) {
                    /*合并攻略评论数据*/
                    $.merge(commentData, data.list);
                    pages = data.pages;
                    /*包装数据,准备渲染到页面上*/
                    //var json = {list: commentData};
                    /*list:攻略点评分页查询结果数组;pages:分页查询出攻略点评分页总页数*/
                    $("#comment").renderValues({list: commentData, pages: data.pages}, {
                        getStar: function (item, value) {
                            var starhtml = '';
                            var unStarhtml = '';
                            var value = parseInt(value);
                            for (let i = 0; i < value; i++) {
                                starhtml += '<i class="fa fa-star"></i>';
                            }
                            for (let i = 0; i < 5 - value; i++) {
                                unStarhtml += '<i class="fa fa-star-o"></i>';
                            }
                            $(item).html(starhtml + unStarhtml);
                        },
                        getContent: function (item, value) {
                            if (value.length > 60) {
                                value = value.substring(0, 60) + "...";
                            }
                            $(item).html(value);
                        },
                        getImgUrls: function getImgUrls(item, value) {
                            var split = value.split(";");
                            var temp = "";
                            for (var i = 0; i < split.length - 1; i++) {
                                temp += '<li><img data-src="' + split[i] + '" src="' + split[i] + '" class="imgBtn"></li>';
                            }
                            $(item).html(temp);

                        },
                        getHref: function (item, value) {
                            var href = $(item).data("href");
                            $(item).attr("href", href + value);
                        }
                    })
                    /*图片点击,拼接显示图片*/
                    $(".comment-img img").click(function () {
                        $(document).dialog({
                            titleShow: false,
                            overlayClose: true,
                            content: '<div style="text-align: center;"><img width="100%" src="' + $(this).attr('src') + '"></div>'
                        });
                    })
                })
                currentInput.val(parseInt(pageNum)+1);
            }

            /*页面点击"点评"按钮,跳转到攻略点评页面*/
            $("#commentBtn").click(function () {
                window.location.href = "/mine/addComment.html?strategyId=" + strategyId;
            });

            //大家都再看
            $.get("/strategies/" + params.strategyId + "/hots", function (data) {
                $('.hots').renderValues({list: data}, {
                    getHot: function (item, value) {
                        var href = $(item).data("href");
                        $(item).attr("href", href + value);
                        $(".hots").html(data.title);
                    }
                })
            });
            /*显示更多的评论*/
            $('._j_add_more_button').click(function () {
                var currentPage = currentInput.val();
                if (currentPage <= pages) {
                    query();
                } else {
                    $(document).dialog({
                        type: 'notice',
                        infoText: '没有更多私信了!!!',
                        autoClose: 1000
                    });
                }
            })
        });
    </script>

</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜索旅行攻略">
            </div>
        </div>
    </div>
</div>

<div class="container strategies">
    <h5 class="title"></h5>
    <small><span>0</span>人阅读过此攻略</small>
    <div class="focus">
        <i class="fa fa-heart"><span> 0</span> 收藏</i>
        <i class="fa fa-thumbs-up"><span> 0</span> 点赞</i>
        <button class="btn">想去</button>
        <button class="btn">去过</button>
    </div>
</div>
<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab">
    <li class="nav-item ">
        <a class="nav-link active" id="pills-catalog-tab" data-toggle="pill" href="#pills-catalog">
            <span>攻略目录</span>
        </a>
    </li>
    <li class="nav-item">
        <a class="nav-link " id="pills-comment-tab" data-toggle="pill" href="#pills-comment">
            <span>骡友点评</span>
        </a>
    </li>
</ul>
<div class="tab-content " id="pills-tabContent">
    <div class="tab-pane fade show active" id="pills-catalog">
        <div class="container hot">
            <!--大家都在看-->
            <div class="hots">
                <h6>大家都在看</h6>
                <div render-loop="list">
                    <div>
                        <a data-href="travelContent.html?id=" render-key="list.id" render-fun="getHot">
                            <button class="btn" render-html="list.title"></button>
                        </a>
                    </div>
                </div>
            </div>

            <div class="catalogs">
                <div render-loop="list">
                    <div class="container detail">
                        <h6 render-key="list.name" render-fun="getName"></h6>
                        <div render-loop="list.details">
                            <a data-href="strategyDetails.html?id=" render-key="list.details.id" render-fun="getHref">
                                <button class="btn" render-html="list.details.title"></button>
                            </a></div>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <div class="tab-pane fade" id="pills-comment">

        <div class="container tag">
            <h6>骡友标签</h6>
            <div render-loop="list">
                <span render-html="list.name"></span>
            </div>
        </div>
        <hr>

        <div id="comment">
            <input type="hidden" name="currentPage" value="1">
            <input type="hidden" name="pageSize" value="5">
            <input type="hidden" name="pages" render-value="pages">
            <div render-loop="list">
                <div class="container row comment">
                    <div class="col-2 comment-head">
                        <!--跳转到个人页面-->
                        <a data-href="userProfiles.html?authorId=" render-key="list.user.id" render-fun="getHref">
                            <img class="rounded-circle" render-src="list.user.headImgUrl">
                        </a>
                    </div>
                    <div class="col comment-right">
                        <p class="authorName"><span render-html="list.user.nickName"></span></p>
                        <span class="comment-star" render-key="list.starNum" render-fun="getStar"></span>
                        <span class="comment-date" render-html="list.createTime"></span>
                        <div class="comment-content">
                            <a data-href="strategyComment.html?commentId=" render-key="list.id" render-fun="getHref">
                                <p render-key="list.content" render-fun="getContent"></p>
                            </a>
                        </div>

                        <ul class="comment-img" render-key="list.imgUrls" render-fun="getImgUrls"></ul>

                        <div class="d-flex icon">
                            <a data-href="strategyComment.html?commentId=" render-key="list.id" render-fun="getHref">
                                <i class="fa  fa-commenting-o " style="margin-right: 10px"> 评论 </i>
                                <i class="fa fa-thumbs-o-up"> <span>0</span> </i>
                            </a>
                        </div>

                    </div>
                </div>

            </div>
        </div>
        <!--显示更多的评论-->
        <div class="show_more"><a role="button" class="_j_more _j_add_more_button" title="显示更多评论">显示更多评论<i
                class="public_sprite"></i></a></div>
    </div>

</div>
</div>

<div class="operation">
    <button class="btn">加入旅行单</button>
    <button class="btn" id="commentBtn">点评</button>
</div>


</body>
</html>